package cn.edu.whu.irlab.web;

import cn.edu.whu.irlab.model.User;
import cn.edu.whu.irlab.model.UserQuestionConcern;
import cn.edu.whu.irlab.model.UserStatistic;
import cn.edu.whu.irlab.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;

/**
 * Created by Roger on 2016/8/1.
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private UserStatisticService usService;
    @Autowired
    private QuestionService questionService;
    @Autowired
    private UserQuestionConcernService uqcService;
    @Autowired
    private UserAnswerCollectionService uacService;
    @Autowired
    private UserTopicService utService;
    @Autowired
    private UserGroupService ugService;

    @ModelAttribute
    public void getBaseInfo(Model model){
        Integer userId = 1;
        User user = userService.selectByPrimaryKey(userId);
        UserStatistic userStatistic = usService.selectByPrimaryKey(userId);
        model.addAttribute("user", user);
        model.addAttribute("userStatistic", userStatistic);
    }


    @RequestMapping(method = RequestMethod.GET)
    public String getUser(HttpSession session, Model model){
//        model.addAttribute("user", userService.selectByPrimaryKey((Integer)session.getAttribute("userId")));
        return "redirect:/user/question";
    }

    @RequestMapping(value = "/question", method = RequestMethod.GET)
    public String getUserQuestion(Model model){
        return "user/userQuestion";
    }

    @RequestMapping(value = "/answer", method = RequestMethod.GET)
    public String getUserAnswer(Model model){
        return "user/userAnswer";
    }

    @RequestMapping(value = "/collection", method = RequestMethod.GET)
    public String getUserCollection(Model model){
        return "user/userCollection";
    }

    @RequestMapping(value = "/group", method = RequestMethod.GET)
    public String getUserGroup(Model model){
        Integer userId = 1;
        User user = userService.selectByPrimaryKey(userId);
        UserStatistic userStatistic = usService.selectByPrimaryKey(userId);
        model.addAttribute("user", user);
        model.addAttribute("userStatistic", userStatistic);
        return "user/userGroup";
    }

    @RequestMapping(value = "/followee", method = RequestMethod.GET)
    public String getUserFollowee(Model model){
        return "user/userFollowee";
    }

    @RequestMapping(value = "/follower", method = RequestMethod.GET)
    public String getUserFollower(Model model){
        return "user/userFollower";
    }

    @RequestMapping(value = "/topic", method = RequestMethod.GET)
    public String getUserTopic(Model model){
        return "user/userTopic";
    }
}
